package com.lovo.user.mq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class FanoutReceiver {
    @RabbitListener(queues = {"shop.fanout.queue.a"})
    public void receiveA(String content, Message message, Channel channel){
        System.out.println("A队列接收到Fanout交换机的消息："+content);

        try {
            // 确认消息被消费
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    @RabbitListener(queues = {"shop.fanout.queue.b"})
    public void receiveB(String content, Message message, Channel channel){
        System.out.println("B队列接收到Fanout交换机的消息："+content);

        try {
            // 确认消息被消费
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
